﻿/// <summary>
/// 缓动器，用于在持续输出的流中缓慢变化输入值
/// </summary>
public class Retarder
{
    private RangeFloat m_OutputRange;

    private float m_FixedEasingStep;

    private float m_Value;

    public float value
    {
        get
        {
            return m_Value;
        }
        set
        {
            m_Value = m_OutputRange.Clamp(value);
        }
    }

    public Retarder(float easingStep, RangeFloat outputRange)
    {
        m_FixedEasingStep = easingStep;
        m_OutputRange = outputRange;
        value = 0;
    }

    public float DoEasing(long axis)
    {
        if (axis > 0 || axis == 0 && value < -10e-3)
        {
            value += m_FixedEasingStep;
        }
        else if (axis < 0 || axis == 0 && value > 10e-3)
        {
            value -= m_FixedEasingStep;
        }
        else
        {
            value = 0f;
        }
        return value;
    }

    public float DoDynamicEasing(byte axis, float dynamicStep)
    {
        if (axis > 0 || axis == 0 && value < -10e-3)
        {
            value += dynamicStep;
        }
        else if (axis < 0 || axis == 0 && value > 10e-3)
        {
            value -= dynamicStep;
        }
        else
        {
            value = 0f;
        }
        return value;
    }

    public void Reset()
    {
        value = 0;
    }
}